<?php

use think\admin\model\SystemSites;
use think\migration\Migrator;

@set_time_limit( 0 );
@ini_set( 'memory_limit', -1 );

/**
* 系统模块初始化
*/

class AddSites extends Migrator
 {
    /**
    * 数据库初始化
    * @return void
    */

    public function change()
 {
        $sites = [
            [
                'site_name' => 'ggpt',
                'site_url' => 'https://gamegamept.com',
                'api_url' => 'https://gamegamept.com/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => 'oldtoons',
                'site_url' => 'https://oldtoon.world',
                'api_url' => 'https://oldtoon.world/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '麒麟',
                'site_url' => 'https://www.hdkyl.in',
                'api_url' => 'https://www.hdkyl.in/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => 'agsv',
                'site_url' => 'https://www.agsvpt.com',
                'api_url' => 'https://www.agsvpt.com/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '红豆饭',
                'site_url' => 'https://hdfans.org',
                'api_url' => 'https://hdfans.org/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ]
        ];

        foreach ( $sites as $site ) {
            $existingSite = SystemSites::mQuery()->db()->where( 'site_url', $site[ 'site_url' ] )->find();

            if ( !$existingSite ) {
                SystemSites::mQuery()->db()->insert( $site );
            } else {
                echo '站点已存在';
            }
        }
    }
}
